INTEGER FUNCTION soal1a()
	IMPLICIT NONE
	EXTERNAL main1
	call main1(1)
	soal1a = 1
END

INTEGER FUNCTION soal1b()
	IMPLICIT NONE
	EXTERNAL main1
	call main1(2)
	soal1b = 1
END

INTEGER FUNCTION soal1c()
	IMPLICIT NONE
	EXTERNAL main1
	call main1(3)
	soal1c = 1
END

INTEGER FUNCTION soal1d()
	IMPLICIT NONE
	EXTERNAL main2
	call main2()
	soal1d = 1
END

! SOAL 4
INTEGER FUNCTION soal4()
	IMPLICIT NOne
	EXTERNAL main1
	call main1(4)
	soal4 = 1
END
! END SOAL 4

SUBROUTINE main1(choice)
	IMPLICIT NONE
	EXTERNAL bagi,grafik
	WINAPP
	DOUBLE PRECISION epsilon,a,b,hasil,min_v,max_v
	CHARACTER*10 metode(3)
	DATA metode/'bagi dua', 'falsi', 'secant'/
	INTEGER i,k,pil,choice
	COMMON /AREA1/ a,b,k,hasil
	COMMON /AREA2/ pil
	PARAMETER (epsilon = 0.000001)

	pil = choice
	
	k = 1
	a=0.0D0
	b=0.0D0
	hasil = 0.0D0
	
	IF(choice.EQ.1) THEN
		min_v=0.0D0
		max_v=0.9D0
	ELSE
		IF(choice.EQ.2) THEN
			min_v= 0.0D0
			max_v= 100.0D0
		ELSE
			min_v= 0.0D0
			max_v= 100.0D0
		END IF
	END IF

	i	= winio@('%ca[Bagi Dua]%bg[grey]&')
	i	= winio@('Metode =&')
	i  	= winio@('%`ls%ta&',metode,3,k)
	i	= winio@('%2tl&',5,15)
	i	= winio@('%fl&', min_v, max_v) 
	i	= winio@('%itvalue 1%`it=&')
	i	= winio@('%rf&',a)
	i	= winio@('%fl&', min_v, max_v)
	i	= winio@('%ta%itvalue 2%`it=&')
	i	= winio@('%rf&',b)
	i	= winio@('%2nl%cn%40^bt[CARI]&',bagi)
	i	= winio@('%2nl%cn%ob[named_c][Hasil]&')
	i	= winio@('%nl%dy%`rf&',0.0D0,hasil)
	i	= winio@('%nlDitemukan setelah &')
	i	= winio@('%cb%4nl%cn%bt[PRINT]&')
	IF(choice.NE.4) THEN
		i	= winio@('%^bt[LIHAT GRAFIK]&',grafik)
	END IF
	i	= winio@('%bt[BACK]')
END


INTEGER FUNCTION bagi() 
	EXTERNAL form1A, form1B, form1C,form4
	DOUBLE PRECISION a,b,x1,x2,galat,epsilon_mesin,hasil,epsilon,form1A,form1B,form1C, form4
	INTEGER pil
	COMMON /AREA1/ a,b,k,hasil
	COMMON /AREA2/ pil
	
	PARAMETER (galat = 0.000001, epsilon = 0.000001)
	x1 		= a
	x2 		= b
	epsilon_mesin = hitung_epsilon_mesin()	
	
	print*, " "
	
	IF(k.EQ.1) THEN 
		! bagi dua
		IF(pil.EQ.1) THEN
			call bagi_dua_galat(form1A,epsilon_mesin, galat,  x1, x2 , hasil)
		ELSE
			IF(pil.EQ.2) THEN
				call bagi_dua_galat(form1B,epsilon_mesin, galat,  x1, x2 , hasil)
			ELSE
				IF(pil.EQ.3) THEN
					call bagi_dua_galat(form1C,epsilon_mesin, galat,  x1, x2 , hasil)
				ELSE
					call bagi_dua_galat(form4,epsilon_mesin, galat, x1, x2, hasil)
				END IF
			END IF
		END IF
	ELSE
		IF(k.EQ.2) THEN
			! falsi
			IF(pil.EQ.1) THEN
				call regula_falsi_galat(form1A,epsilon_mesin,delta,galat,x1,x2,hasil)
			ELSE
				IF(pil.EQ.2) THEN
					call regula_falsi_galat(form1B,epsilon_mesin,delta,galat,x1,x2,hasil)
				ELSE
					IF(pil.EQ.3) THEN
						call regula_falsi_galat(form1C,epsilon_mesin,delta,galat,x1,x2,hasil)
					ELSE
						call regula_falsi_galat(form4,epsilon_mesin,delta,galat,x1,x2,hasil)
					END IF
				END IF
			END IF
		ELSE
			! secant
			IF(pil.EQ.1) THEN
				call secant_galat(form1A,epsilon_mesin,galat,x1,x2,hasil)
			ELSE
				IF(pil.EQ.2) THEN
					call secant_galat(form1B,epsilon_mesin,galat,x1,x2,hasil)
				ELSE
					IF(pil.EQ.3) THEN
						call secant_galat(form1C,epsilon_mesin,galat,x1,x2,hasil)
					ELSE
						call secant_galat(form4,epsilon_mesin,galat,x1,x2,hasil)
					END IF
				END IF
			END IF
		END IF
	END IF
	
	bagi = 1
END

INTEGER FUNCTION grafik()

	COMMON /AREA2/ pil
	INTEGER i, N, j, pil
	PARAMETER (N=999)
	DOUBLE PRECISION y(N), x, inc
	
	IF(pil.EQ.1) THEN
		inc = 0.01D0
		x = 0.001
		DO i=1,N
			y(i)= form1A(x)
			x	= x + 0.001
		END DO
	ELSE
		inc = 0.01D0
		x = 0.01
		IF(pil.EQ.2) THEN
			DO i=1,N
				y(i)= form1B(x)
				x	= x + 0.01
			END DO
		ELSE
			DO i=1,N
				y(i)= form1C(x)
				x	= x + 0.01
			END DO
		END IF
	END IF
	
	j	= winio@('%ca[Grafik]%bg[grey]&')		
	j	= winio@('%pl[x_axis=x, y_axis=y, y_max=10, title="Grafik fungsi",colour=red,y_min=-10]&',400,600,N,0.0D0,inc,y)
	j	= winio@('%ff%nl%cn%bt[OK]')
	
	grafik = 1

END

! SOAL 1D

SUBROUTINE main2() 
	IMPLICIT NONE
	EXTERNAL potong, grafik2
	INTEGER i, l, r(2)
	CHARACTER*20 metode2(2)
	DOUBLE PRECISION x,y
	DATA metode2/'jacobi', 'newton-rhapton'/r/1,0/
	COMMON /AREA3/ x,y,r,l
	
	x = 0.0D0
	y = 0.0D0
	l = 1
	
	i 	= winio@('%ca[Titik Potong]%bg[grey]&')
	i	= winio@('Metode =&')
	i	= winio@('%`ls%ta&', metode2, 2, l)
	i	= winio@('%2nlTebakan awal=&')
	i	= winio@('%2`ga&',r(1),r(2))
	i	= winio@('%rb[(-1.0, 1.0)]&',r(1))
    i	= winio@('%1ta%rb[(3,0, -3,4)]%2nl&',r(2))
	i	= winio@('%nl%cn%20^bt[CARI]&',potong)
	i	= winio@('%2nl%cn%ob[named_c][Hasil]&')
	i	= winio@('%nl%dyx =%`rf&',0.0D0,x)
	i	= winio@('%nl%dyy =%`rf&',0.0D0,y)
	i	= winio@('%cb%3nl%cn%^bt[GRAFIK]&', grafik2)
	i	= winio@('%1ta%bt[BACK]')
	
END

INTEGER FUNCTION potong() 
	IMPLICIT NONE
	EXTERNAL form1D_x, form1D_y, form1D_x_proc, form1D_y_proc
	INTEGER r(2),l
	DOUBLE PRECISION x,y, external, epsilon
	
	PARAMETER (epsilon = 0.000001)
	COMMON /AREA3/ x,y,r,l

	IF(l.EQ.1) THEN
		!jacobi
		IF(r(1).EQ.1) THEN
			x = -1.0
			y = 1.0
			call lelaran_jacobi(form1D_x,form1D_y, epsilon, x, y)
		ELSE
			x = 3.0
			y = -3.4
			call lelaran_jacobi(form1D_x, form1D_y, epsilon,x,y)
		END IF	
	ELSE
		!nrp
		IF(r(1).EQ.1) THEN
			x = -1.0
			y = 1.0
			call nrp(form1D_x_proc, form1D_y_proc, epsilon,x,y)
		ELSE
			x = 3.0
			y = -3.4
			call nrp(form1D_x_proc, form1D_y_proc, epsilon,x,y)
		END IF
	END IF
	
	potong = 1
END	

INTEGER FUNCTION grafik2()
	
	INTEGER i, N, j
	PARAMETER(N = 299)
	DOUBLE PRECISION y(N), y2(N), y1, x
	
	x = -1
	y1 = 0
	
	DO i=1, N
		y(i) = 	form1D_y(x, y1)
		y2(i) = form1D_x_2(x, y1) 
		x 	 = x + 0.01
	END DO
	
	j	= winio@('%ca[Grafik]%bg[grey]&')		
j	= winio@('%pl[x_axis=x,y_axis=y,y_max=4,title="Grafik",n_graphs=2,colour=blue,y_min=-4]&',400,600,N,0.0D0,0.01D0,y,y2)
	j	= winio@('%ff%nl%cn%bt[OK]')
	
	grafik2 = 1
	
END

! SOAL 2 GAN
INTEGER FUNCTION soal2()
	IMPLICIT NONE
	EXTERNAL main_soal2	
	call main_soal2()
	
	soal2 = 1
END

SUBROUTINE main_soal2() 
	IMPLICIT NONE
	INTEGER i
	EXTERNAL hitung, grafik3
	WINAPP
	DOUBLE PRECISION a, result
	COMMON /AREA4/ result, a
	a 	= 0.0D0
	i	= winio@('%ca[Soal 2]%bg[grey]&')
	i	= winio@('%2nl%cn%itNilai awal%`it  = &')
	i	= winio@('%rf&',a)
	i	= winio@('%fl&', 0.0D0, 200.0D0)
	i	= winio@('%2nl%cn%40^bt[CARI]&',hitung)
	i	= winio@('%2nl%cn%ob[named_c][Hasil]&')
	i	= winio@('%nl%dy%`rf&',0.0D0,result)
	i	= winio@('%cb%4nl%cn%bt[PRINT]&')
	i	= winio@('%^bt[LIHAT GRAFIK]&',grafik3)
	i	= winio@('%bt[BACK]')
	
END

INTEGER FUNCTION hitung()
	EXTERNAL form2,form2_aksen,form2_double_aksen
	DOUBLE PRECISION a,result,form2,form2_aksen,form2_double_aksen,epsilon
	COMMON /AREA4/ result,a
	PARAMETER(epsilon = 1.E-5)
	call newton_raphson(form2,form2_aksen,form2_double_aksen,a,epsilon)
	result 	= a
	hitung	= 1
END

INTEGER FUNCTION grafik3()
	INTEGER i, N, j
	PARAMETER(N = 999)
	DOUBLE PRECISION y(N), y2(N), y1, x
	x = 0
	y1 = 0
	DO i=1, N
		y(i) = 	form2(x)
		x 	 = x + 0.01
	END DO
	j	= winio@('%ca[Grafik]%bg[grey]&')		
	j	= winio@('%pl[x_axis=x,y_axis=y,y_max=15,title="Grafik",colour=blue,y_min=-15]&',400,600,N,0.0D0,0.01D0,y)
	j	= winio@('%ff%nl%cn%bt[OK]')
	grafik3 = 1
END
	
! SOAL NO 3
INTEGER FUNCTION soal3()
	IMPLICIT NONE
	EXTERNAL main_soal3	
	call main_soal3()
	soal3 = 1
END

SUBROUTINE main_soal3() 
	IMPLICIT NONE
	EXTERNAL hitung3
	WINAPP
	INTEGER i
	DOUBLE PRECISION a, b,r1,r2,r3,r4,r5,r6
	COMMON /AREA5/a,b,r1,r2,r3,r4,r5,r6
	
	a 	= 0.0D0
	b	= 0.0D0
	r1 	= 0.0D0
	r2 	= 0.0D0
	r3 	= 0.0D0
	r4 	= 0.0D0
	r5 	= 0.0D0
	r6 	= 0.0D0
	i	= winio@('%ca[Soal 3]%bg[grey]&')
	i	= winio@('%2tl&',5,15)
	i	= winio@('%fl&', 0.0D0, 100.0D0) 
	i	= winio@('%itvalue 1%`it=&')
	i	= winio@('%rf&',a)
	i	= winio@('%fl&', 0.0D0, 100.0D0)
	i	= winio@('%ta%itvalue 2%`it=&')
	i	= winio@('%rf&',b)
	i	= winio@('%fl&', 0.0D0, 200.0D0)
	i	= winio@('%2nl%cn%40^bt[CARI]&',hitung3)
	i	= winio@('%2nl%cn%ob[named_l][Xaf  = 0.99]&')
	i	= winio@('%nl%dyBagi dua =%`rf&',0.0D0,r1)
	i	= winio@('%nl%dyFalsi	   =%`rf&',0.0D0,r2)
	i	= winio@('%nl%dySecant	  =%`rf&',0.0D0,r3)
	i	= winio@('%cb%2nl%cn%ob[named_l][Xaf  = 0.995]&')
	i	= winio@('%nl%dyBagi dua =%`rf&',0.0D0,r4)
	i	= winio@('%nl%dyFalsi	   =%`rf&',0.0D0,r5)
	i	= winio@('%nl%dySecant	  =%`rf&',0.0D0,r6)
	i	= winio@('%cb%4nl%cn%bt[BACK]')
END

INTEGER FUNCTION hitung3()
	EXTERNAL hitung_epsilon_mesin
	COMMON /AREA5/ a,b,r1,r2,r3,r4,r5,r6
	DOUBLE PRECISION a,b,eps,epsilon_mesin,r1,r2,r3,r4,r5,r6,tempa,tempb
	PARAMETER(eps = 0.000001)
	tempa = a
	tempb = b
	r1 	= 0.0D0
	r2 	= 0.0D0
	r3 	= 0.0D0
	r4 	= 0.0D0
	r5 	= 0.0D0
	r6 	= 0.0D0
	epsilon_mesin = hitung_epsilon_mesin()	
	
	call nomor3(epsilon_mesin,eps,tempa,tempb,r1,r2,r3,r4,r5,r6)

	hitung3	= 1
END

! SOAL 4 GAN




